﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PersonalAlbumModel>" %>
<%@ Import Namespace="PersonalAlbum" %>
<asp:Content ID="loginContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        <%=Model.Localize("Login") %></h2>
    <%-- <p>
        Please enter your username and password below. If you don't have an account,
        please <%= Html.ActionLink("register", "Register") %>.
    </p>
    --%>
    <%= Html.ValidationSummary() %>
    
    <% using (Html.BeginForm("Login", "Account", FormMethod.Post, new { id = "loginForm", defaultbutton = "btnSubmit" ,defaultfocus="username"}))
       { %>
       <%--Html. AntiForgeryToken() --%>
    <div>
        <table>
            <tr>
                <td>
                    <%=Model.Localize("Username")%>:
                </td>
                <td>
                    <%= Html.TextBox("username")%>
                    <%= Html.ValidationMessage("username")%>
                </td>
            </tr>
            <tr>
                <td>
                    <%=Model.Localize("Password")%>:
                </td>
                <td>
                    <%= Html.Password("password")%>
                    <%= Html.ValidationMessage("password")%>
                </td>
            </tr>
            <%--   <tr>
                    <td></td>
                    <td><%= Html.CheckBox("rememberMe") %> Remember me?</td>
                </tr>--%>
            <tr>
                <td>
                   <input type="button" id="btnSubmit" onclick="javascript:doLogin()" value="<%=Model.Localize("Login") %>" />
                </td>
                <td>
                  <%if (Model.Configuration.AllowAddUsers){ %>
                        <%=Html.ActionLink<AccountController>(a => a.Register(), Model.Localize("Login.Register"))%>
                    <%} %>
                   
                </td>
            </tr>
        </table>
    </div>
    <% } %>

    <script type="text/javascript">
        $(document).ready(function() {
            document.getElementById('username').focus();
        });
        function doLogin() {
            var form = document.getElementById("loginForm");
            $.ajax({
                url: form.action,
                type: form.method,
                data: $(form).serialize(),
                dataType: 'json',
                success: function(j) {

                    if (j.error) {
                        alert('<%=Model.Localize("Entry.Error") %>');
                    } else {
                        if (j.success) {
                            window.location.href = j.returnUrl;
                        } else {
                            alert(j.message);
                        }
                    }
                }, error: function(err) {
                    alert('<%=Model.Localize("Entry.Error") %>');
                }
            });
        }
    </script>

</asp:Content>
